home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6260 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: ell@access1.digex.net (Ell)
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: [Q] Interface vs. Implementation Inheritance
  5. Date: 10 Feb 1996 14:32:24 -0000
  6. Organization: The Universe
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: harkness@airmail.net
  9. Message-ID: <4fia9o$qm3@netlab.cs.rpi.edu>
  10. NNTP-Posting-Host: netlab.cs.rpi.edu
  11. X-Original-Date: 10 Feb 1996 06:29:30 GMT
  12.  
  13.  K. Lewis (lewikk@grasshopper.aud.alcatel.com) wrote: 
  14. : When I think of substitutability, I think of subtyping.  I think a
  15. : type is substitutable for its supertype, eg, "everywhere I use a
  16. : rectangle I can use a square because a square _is a_ rectangle."
  17.  
  18. Not every class in C++ that is derived from a base class, and assigned to
  19. a base class pointer is required to, or should be a logical "is-a" subtype
  20. of the base class.  As the C++ FAQ book points out, publicly inherited
  21. classes need only satisfy the promises given by, and require no more than
  22. the base class.  [However, it is true that most publicly derived C++
  23. classes will in fact be logical "is-a" subtypes of the base.]
  24.  
  25. The point I make is that we can also view a system as having dynamically
  26. substitutable parts.  Whether by using a base class pointer as above in
  27. C++, or interface specification (contracts, or protocols) a la CLOS, and
  28. Smalltalk, the parts of a system may be changed during run-time
  29. (dynamically).  Such changes may occur on both a micro (object) and macro
  30. (subsystem/category) level.  This allows a system to fulfill more than one
  31. purpose, and to be robust in the face of widely varying run-time
  32. circumstances. 
  33.  
  34. With respect to C++, sometimes the thing we want to do with a system is to
  35. substitute one, or more of its parts with existing parts in the
  36. environment without regard to whether, or not the parts being swapped in
  37. are logical "is-a" subtypes of the base pointer being used to do the
  38. swapping.  In C++ to do such swapping, the classes being swapped must be
  39. physically inherited siblings of the base class.  In other languages,
  40. objects need only possess the protocol which allows them to be used in a
  41. given context (or to paraphrase one Internet contributor, to be used in a
  42. given "socket").  They do not have to be "is-a" subtypes of one or another
  43. class. 
  44.  
  45. Cheers,
  46.  
  47. Elliott
  48.  
  49.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  50.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  51.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  52.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  53.